package ink.lovejinhu.leetcode;

import java.util.HashSet;

/**
 * @Author: jin
 * @Date: 2021/9/14 23:22
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0929 {
    /**
     * 独特的邮件地址
     *
     * @param emails
     * @return
     */
    public int numUniqueEmails(String[] emails) {
        HashSet<String> strings = new HashSet<>();
        for (int i = 0; i < emails.length; i++) {
            strings.add(delete(emails[i]));
        }
        System.out.println(strings);
        return strings.size();
    }

    public String delete(String emails) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < emails.length(); i++) {
            if (emails.charAt(i) == '@') {
                stringBuilder.append(emails.substring(i, emails.length()));
                return stringBuilder.toString();
            }
            if (emails.charAt(i) == '.') {
                continue;
            } else if (emails.charAt(i) == '+') {
                for (int j = i + 1; j < emails.length(); j++) {
                    if (emails.charAt(j) == '@') {
                        stringBuilder.append(emails.substring(j, emails.length()));
                        return stringBuilder.toString();
                    }
                }
            } else {
                stringBuilder.append(emails.charAt(i));
            }

        }
        return stringBuilder.toString();

    }

    public static void main(String[] args) {
        Solution_0929 solution_0929 = new Solution_0929();
        String[] test = {"test.email+alex@leetcode.com", "test.email@leetcode.com"};
        int i = solution_0929.numUniqueEmails(test);
    }
}
